package org.example.current.gateway;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;
import reactor.core.publisher.Mono;

import java.time.LocalDateTime;

/**
 * @author jie.luo
 * @description
 * @since 2020-06-17
 */
@EnableDiscoveryClient
@SpringBootApplication
public class CurrentGatewayApplication {
    public static void main(String[] args) {
        SpringApplication.run(CurrentGatewayApplication.class, args);
    }

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Bean
    @Order(1)
    public GlobalFilter executionTimeFilter() {
        return (exchange, chain) -> {
            logger.debug(exchange.getRequest().getURI().getRawPath() + "开始时间 ： " + LocalDateTime.now());
            return chain.filter(exchange).then(Mono.fromRunnable(() -> {
                logger.debug(exchange.getRequest().getURI().getRawPath() + "结束时间 ： " + LocalDateTime.now());
            }));
        };
    }
}
